package com.itheima.demo;

import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import com.itheima.utils.MapperUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/*
    代理开发模式
 */
public class DemoMapper {
    public static void main(String[] args) throws IOException {
        SqlSession session = MapperUtil.getSession();
        /*InputStream is = Resources.getResourceAsStream("sql.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        session = factory.openSession();*/
        //4.获取Mapper代理对象
        UserMapper mapper = session.getMapper(UserMapper.class);
        //5.调用接口方法
        List<User> list = mapper.findAll();
        System.out.println(list);
        /*//6.事务提交
        session.commit();
        //7.释放资源
        session.close();
        is.close();*/
        MapperUtil.close(session);
    }
}
